home *** CD-ROM | disk | FTP | other *** search
- /*
- * Project: SimpleApp
- *
- * Filename: SimpleAppWindows.c
- *
- * Author: Marco Piovanelli
- *
- * Revision History:
- *
- * 1996.05.24 MP created this file
- *
- */
-
- #include "SimpleApp.h"
-
- #ifndef __ALIASES__
- #include <Aliases.h>
- #endif
-
- #include "DirectoryPopup.h"
- #include "FinderObjects.h"
-
- void CalcSizeBox ( WindowRef macWindow, Rect * iconRect ) ;
- void DrawSizeBox ( WindowRef macWindow, Boolean validate = false ) ;
-
- OSErr CreateWindow ( const FSSpec * fileSpec )
- {
- WindowRef macWindow ;
- AliasHandle alias = nil ;
-
- macWindow = GetNewCWindow ( kWindowTemplateID, nil, ( WindowRef ) -1L ) ;
- if ( macWindow == nil )
- {
- return memFullErr ;
- }
-
- if ( fileSpec != nil )
- {
- SetWTitle ( macWindow, fileSpec -> name ) ;
- if ( ( NewAlias ( nil, fileSpec, & alias ) == noErr ) &&
- ( alias != nil ) )
- {
- SetWRefCon ( macWindow, ( SInt32 ) alias ) ;
- }
- }
-
- ShowWindow ( macWindow ) ;
-
- return noErr ;
- }
-
- OSErr DestroyWindow ( WindowRef macWindow )
- {
- AliasHandle alias = ( AliasHandle ) GetWRefCon ( macWindow ) ;
-
- if ( alias != nil )
- {
- DisposeHandle ( ( Handle ) alias ) ;
- SetWRefCon ( macWindow, 0 ) ;
- }
-
- DisposeWindow ( macWindow ) ;
- return noErr ;
- }
-
- void DoGoAway ( WindowRef macWindow, const EventRecord & event )
- {
- DestroyWindow ( macWindow ) ;
- }
-
- void DoContent ( WindowRef macWindow, Point hitPt, const EventRecord & event )
- {
- }
-
- void DoDrag ( WindowRef macWindow, Point hitPt, const EventRecord & event )
- {
- if ( event . modifiers & cmdKey )
- {
- AliasHandle alias ;
- FSSpec fileSpec ;
- Boolean wasChanged = false ;
-
- if ( ( ( alias = ( AliasHandle ) GetWRefCon ( macWindow ) ) != nil ) &&
- ( ResolveAlias ( nil, alias, & fileSpec, & wasChanged ) == noErr ) )
- {
- if ( wasChanged )
- {
- SetWTitle ( macWindow, fileSpec . name ) ;
- }
- if ( TrackDirectoryPopup ( & fileSpec, macWindow, hitPt ) )
- {
- OpenFinderObject ( & fileSpec ) ;
- return ;
- }
- }
- }
-
- Rect bounds = ( * GetGrayRgn ( ) ) -> rgnBBox ;
- DragWindow ( macWindow, hitPt, & bounds ) ;
- }
-
- void DoZoom ( WindowRef macWindow, SInt16 partCode, const EventRecord & event )
- {
- }
-
- void DoGrow ( WindowRef macWindow, Point hitPt, const EventRecord & event )
- {
- const Rect growRect = { 80, 224, 32000, 32000 } ;
- SInt32 growResult ;
-
- if ( ( growResult = GrowWindow ( macWindow, hitPt, & growRect ) ) != 0 )
- {
- Rect iconRect ;
-
- SetPortWindowPort ( macWindow ) ;
- CalcSizeBox ( macWindow, & iconRect ) ;
- EraseRect ( & iconRect ) ;
- SizeWindow ( macWindow, SInt16 ( growResult ), SInt16 ( growResult >> 16 ), false ) ;
- DrawSizeBox ( macWindow, true ) ;
- }
- }
-
- void CalcSizeBox ( WindowRef macWindow, Rect * iconRect )
- {
- Rect portRect = GetWindowPort ( macWindow ) -> portRect ;
-
- iconRect -> top = portRect . bottom - 15 ;
- iconRect -> left = portRect . right - 15 ;
- iconRect -> bottom = portRect . bottom ;
- iconRect -> right = portRect . right ;
- }
-
- void DrawSizeBox ( WindowRef macWindow, Boolean validate )
- {
- GrafPtr savePort ;
- RgnHandle saveClip ;
- Rect r ;
-
- // set up the port
- GetPort ( &savePort ) ;
- SetPortWindowPort ( macWindow ) ;
-
- // save the clip region
- saveClip = NewRgn ( ) ;
- GetClip ( saveClip ) ;
-
- // calculate the grow icon rect
- CalcSizeBox ( macWindow, & r ) ;
-
- // set clip region to grow icon rect
- ClipRect ( & r ) ;
-
- // call DrawGrowIcon
- DrawGrowIcon ( macWindow ) ;
-
- // if validate is true, remove the grow icon rect from the update region
- if ( validate )
- {
- ValidRect ( & r ) ;
- }
-
- // restore old clip region
- SetClip ( saveClip ) ;
- DisposeRgn ( saveClip ) ;
-
- // restore old port
- SetPort ( savePort ) ;
- }
-
- void DoUpdate ( WindowRef macWindow, RgnHandle invalidRgn )
- {
- DrawSizeBox ( macWindow ) ;
- }
-
- void DoActivate ( WindowRef macWindow, Boolean isActivating )
- {
- DrawSizeBox ( macWindow, true ) ;
- }
-